<?php
function template_dotastats_above()
{
	global $context, $scripturl, $txt;
	
	// Output the dotastats button bar
	echo '
	<div id="dotastats_frame">
		<div id="ds_infobar_menu">
			<table cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td class="mirrortab_first">&nbsp;</td>';

		foreach ($context['sort_links'] as $link)
		{
			if ($link['selected'])
				echo '
						<td class="mirrortab_active_first">&nbsp;</td>
						<td valign="top" class="mirrortab_active_back">
							<a href="', $scripturl, '?action=dotastats', (!empty($link['action']) ? ';sa=' . $link['action'] : ''), '">', $link['label'], '</a>
						</td>
						<td class="mirrortab_active_last">&nbsp;</td>';
			else
				echo '
						<td valign="top" class="mirrortab_back">
							<a href="', $scripturl, '?action=dotastats', (!empty($link['action']) ? ';sa=' . $link['action'] : ''), '">', $link['label'], '</a>
						</td>';
		}

			echo '
					<td class="mirrortab_last">&nbsp;</td>
				</tr>
			</table>
		</div>';
		
	// Output the dotastats infobar
	echo '
		<ul id="dotastats_infobar">
			<li><strong>', $txt['dotastats_rankedplayers'], ':</strong> ', $context['dotastats']['infobar']['rankedplayers'], '</li>
			<li><strong>', $txt['dotastats_allplayers'], ':</strong> ', $context['dotastats']['infobar']['totalplayers'], '</li>
			<li><strong>', $txt['dotastats_games'], ':</strong> ', $context['dotastats']['infobar']['totalgames'], '</li>
			<li><strong>', $txt['dotastats_bans'], ':</strong> ', $context['dotastats']['infobar']['totalbans'], '</li>
			<li><strong>', $txt['dotastats_admins'], ':</strong> ', $context['dotastats']['infobar']['totaladmins'], '</li>
		</ul>
	</div>';
}

function template_dotastats_below()
{
	global $context;
	
	// Output the dotastats credit information
	echo '
	<div id="dotastats_credits">
		<ul class="smalltext">
			<li>SMF modification by James A. Blake</li>
			<li>GHost++ modifications by Arius</li>
			<li>Credits to VinnieDaPooh, <a href="http://fourzerosix.net/">fourzerosix</a>, Varlock, and <a href="http://www.forum.codelain.com/">Codelain</a></li>
		</ul>
	</div>';
}

function template_main()
{
	global $context, $scripturl, $txt, $settings;
	
	// Output various displays based on the subaction
	switch ($context['dotastats']['action'])
	{
		// Output the playerlist table
		case 'playerlist':
			if (isset($context['dotastats']['players']))
			{
				echo '
	<div id="dotastats_frame">
		<script type="text/javascript">
			$(document).ready(function(){
				// Table sorting function
				$("#playerlist > table").tablesorter({ 
					widgets: ["zebra"]
				});
			});
		</script>
		<div id="playerlist">
			<table class="dotastats_table">
				<thead>
					<tr class="catbg">
						<th class="cell_text">', $txt['dotastats_name'], '</th>
						<th class="cell_number">', $txt['dotastats_score'], '</th>
						<th class="cell_number">', $txt['dotastats_games'], '</th>
						<th class="cell_number">', $txt['dotastats_gamesday'], '</th>
						<th class="cell_number">', $txt['dotastats_wins'], '</th>
						<th class="cell_number">', $txt['dotastats_losses'], '</th>
						<th class="cell_number">', $txt['dotastats_winloss'], '</th>
						<th class="cell_dt">', $txt['dotastats_lastgame'], '</th>
					</tr>
				</thead>
				<tbody>';
			
				$totalscore = 0;
				$totalgames = 0;
				$totalgamesperday = 0;
				$totalwins = 0;
				$totallosses = 0;
				$totalwinpercentage = 0;
				$rankedplayers = count($context['dotastats']['players']);
				
				foreach($context['dotastats']['players'] as $playername => $playerinfo)
				{
					echo '
					<tr>
						<td class="cell_text"><a href="', $scripturl, '?action=dotastats;sa=playerdetail;name=', $playername, '">', $playername, '</a></td>
						<td class="cell_number">', number_format($playerinfo['score'], 2), '</td>
						<td class="cell_number">', $playerinfo['totalgamesplayed'], '</td>
						<td class="cell_number">', $playerinfo['gamesperday'], '</td>
						<td class="cell_number">', $playerinfo['wins'], '</td>
						<td class="cell_number">', $playerinfo['losses'], '</td>
						<td class="cell_number">', number(($playerinfo['wins'] / ($playerinfo['wins'] + $playerinfo['losses'])) * 100, 2), '%</td>
						<td class="cell_dt"><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $playerinfo['lastgameid'], '">', $playerinfo['lastgamedt'], '</a></td>
					</tr>';
				
					// Add stats up so we can display averages in the footer
					$totalscore += $playerinfo['score'];
					$totalgames += $playerinfo['totalgamesplayed'];
					$totalgamesperday += $playerinfo['gamesperday'];
					$totalwins += $playerinfo['wins'];
					$totallosses += $playerinfo['losses'];
					$totalwinpercentage += ($playerinfo['wins'] / ($playerinfo['wins'] + $playerinfo['losses'])) * 100;
				}

				echo '
				</tbody>
				<tfoot>
					<tr class="playerlist_averages">
						<td><strong>', $txt['dotastats_averages'], '</strong></td>
						<td class="cell_number">', number($totalscore / $rankedplayers, 2), '</td>
						<td class="cell_number">', number($totalgames / $rankedplayers, 0), '</td>
						<td class="cell_number">', number($totalgamesperday / $rankedplayers, 2), '</td>
						<td class="cell_number">', number($totalwins / $rankedplayers, 0), '</td>
						<td class="cell_number">', number($totallosses / $rankedplayers, 0), '</td>
						<td class="cell_number">', number($totalwinpercentage / $rankedplayers, 2), '%</td>
						<td></td>
					</tr>
					<tr class="paging">
						<td colspan="8">
						', $context['dotastats']['paging'], '	
						</td>
					</tr>
				</tfoot>
			</table>
		</div>
		<p class="cell_scoring">', $txt['dotastats_formula'], ': <em>(tw+.1)/(tl+.1)+((2*kpg+apg+1)/(dpg+1))+(ckpg/75+cdpg/5+nkpg/15)/3</em></p>
	</div>';
			}
			else
				echo '
	<div id="ds_game_error" class="ui-state-highlight ui-corner-all">
		<p><span class="ui-icon ui-icon-info"></span>', $txt['dotastats_noplayers'] , '</p>
	</div>';
			break;
		
		// Output the gamelist table
		case 'gamelist':
			if (isset($context['dotastats']['games']))
			{
				echo '
	<div id="dotastats_frame">
		<script type="text/javascript">
			$(document).ready(function(){
				// Table sorting function
				$("#gamelist > table").tablesorter({ 
					widgets: ["zebra"]
				});
			});
		</script>
		<div id="gamelist">
			<table class="dotastats_table">
				<thead>
					<tr class="catbg">
						<th class="cell_text">', $txt['dotastats_gamename'], '</th>
						<th class="cell_dt">', $txt['dotastats_datetime'], '</th>
						<th class="cell_dt">', $txt['dotastats_players'], '</th>
						<th class="cell_text">', $txt['dotastats_status'], '</th>
						<th class="cell_text">', $txt['dotastats_duration'], '</th>
						<th class="cell_dt">', $txt['dotastats_winner'], '</th>
					</tr>
				</thead>
				<tbody>';

				foreach($context['dotastats']['games'] as $gameid => $gameinfo)
				{
					echo '
					<tr>
						<td class="cell_text"><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $gameid, '">', $gameinfo['gamename'], '</a></td>
						<td class="cell_dt">', $gameinfo['datetime'], '</td>
						<td class="cell_dt">', $gameinfo['playercount'], '</td>
						<td class="cell_text">', ($gameinfo['winner'] == 1 || $gameinfo['winner'] == 2) ? $txt['dotastats_complete'] : $txt['dotastats_incomplete'], '</td>
						<td class="cell_text">';
					
					if ($gameinfo['winner'] == 1 || $gameinfo['winner'] == 2)
						echo $gameinfo['minutes'], ' ', $txt['dotastats_minutes_abbr'], ', ', $gameinfo['seconds'], ' ', $txt['dotastats_minutes_abbr'];
					
					echo '</td>
						<td class="cell_dt">';
					
					if ($gameinfo['winner'] == 1)
						echo $txt['dotastats_sentinel'];
					elseif ($gameinfo['winner'] == 2)
						echo $txt['dotastats_scourge'];
					
					echo '</td>
					</tr>';
				}

				echo '
				</tbody>
				<tfoot>
					<tr class="paging">
						<td colspan="8">
						', $context['dotastats']['paging'], '	
						</td>
					</tr>
				</tfoot>
			</table>
		</div>
	</div>';
			}
			else
				echo '
	<div id="ds_game_error" class="ui-state-highlight ui-corner-all">
		<p><span class="ui-icon ui-icon-info"></span>', $txt['dotastats_nogames'] , '</p>
	</div>';
			break;
		
		// Output the banlist table
		case 'banlist':
			if (isset($context['dotastats']['bans']))
			{
				echo '
	<div id="dotastats_frame">
		<script type="text/javascript">
			$(document).ready(function(){
				// Table sorting function
				$("#banlist > table").tablesorter({ 
					widgets: ["zebra"]
				});
			});
		</script>
		<div id="banlist">
			<table class="dotastats_table">
				<thead>
					<tr class=" catbg">
						<th class="cell_text">', $txt['dotastats_realm'], '</th>
						<th class="cell_text">', $txt['dotastats_name'], '</th>
						<th class="cell_text">', $txt['dotastats_ip'], '</th>
						<th class="cell_datetime">', $txt['dotastats_date'], '</th>
						<th class="cell_text">', $txt['dotastats_gamename'], '</th>
						<th class="cell_text">', $txt['dotastats_admin'], '</th>
						<th class="cell_text">', $txt['dotastats_reason'], '</th>
					</tr>
				</thead>
				<tbody>';

				foreach($context['dotastats']['bans'] as $banid => $baninfo)
				{
					echo '
					<tr>
						<td class="cell_text">', $baninfo['server'], '</td>
						<td class="cell_text">', $baninfo['name'], '</td>
						<td class="cell_text">', $baninfo['ip'], '</td>
						<td class="cell_date">', substr($baninfo['date'], 0, 10), '</td>
						<td class="cell_text">', $baninfo['gamename'], '</td>
						<td class="cell_text">', $baninfo['admin'], '</td>
						<td class="cell_longtext">', $baninfo['reason'], '</td>
					</tr>';
				}

				echo '
				</tbody>
				<tfoot>
					<tr class="paging">
						<td colspan="8">
						', $context['dotastats']['paging'], '	
						</td>
					</tr>
				</tfoot>
			</table>
		</div>
	</div>';
			}
			else
				echo '
	<div id="ds_game_error" class="ui-state-highlight ui-corner-all">
		<p><span class="ui-icon ui-icon-info"></span>', $txt['dotastats_nobans'] , '</p>
	</div>';
			break;
		
		// Output detailed information on a single player
		case 'playerdetail':
			$player = $context['dotastats']['playerdetail'];
			
			if ($player)
			{
				echo '
	<div id="dotastats_frame">
		<script>
			$(document).ready(function(){
				$("h3").gradient({
					from:      "E0E0E0",
					to:        "FFFFFF"
				});
			});
		</script>	
		<div id="playerdetail">
			<h1>', $player['name'], '</h1>
			<h3>', $txt['dotastats_playerstats'], '</h3>
			<div id="playerdetail_subcontainer">
				<ul>
					<li><span class="stat_title">Score</span><span>', number($player['score'], 2), '</span></li>
					<li><span class="stat_title">Win/Loss Score</span><span>', number($player['winlossscore'], 2), '</span></li>
					<li><span class="stat_title">Hero Score</span><span>', number($player['heroscore'], 2), '</span></li>
					<li><span class="stat_title">Creep Score</span><span>', number($player['creepscore'], 2), '</span></li>
					<li><span class="stat_title">Kill/Death Ratio</span><span>', number(($player['totalkills'] / $player['totaldeaths']), 2), '</span></li>
					<li><span class="stat_title">Winning Percentage</span><span>', number(($player['wins'] / ($player['wins'] + $player['losses'])) * 100, 2), '%</span></li>
				</ul>
			</div>
			<h3>', $txt['dotastats_performancestats'], '</h3>
			<div id="playerdetail_subcontainer">
				<table class="playerstats_table">
					<thead>
						<tr>
							<th></th>
							<th class="playerstats_col">', $txt['dotastats_most'], '</th>
							<th class="playerstats_col">', $txt['dotastats_average'], '</th>
							<th class="playerstats_col">', $txt['dotastats_total'], '</th>
						</tr>
					<thead>
					<tbody>
						<tr>
							<td class="playerstats_row">', $txt['dotastats_herokills'], '</td>
							<td><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $player['topkillsgameid'], '">', $player['topkills'], '</a></td>
							<td>', number($player['avgkills'], 2), '</td>
							<td>', number($player['totalkills'], 0), '</td>
						</tr>
						<tr>
							<td class="playerstats_row">', $txt['dotastats_herodeaths'], '</td>
							<td><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $player['topdeathsgameid'], '">', $player['topdeaths'], '</a></td>
							<td>', number($player['avgdeaths'], 2), '</td>
							<td>', number($player['totaldeaths'], 0), '</td>
						</tr>
						<tr>
							<td class="playerstats_row">', $txt['dotastats_heroassists'], '</td>
							<td><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $player['topassistsgameid'], '">', $player['topassists'], '</a></td>
							<td>', number($player['avgassists'], 2), '</td>
							<td>', number($player['totalassists'], 0), '</td>
						</tr>
						<tr>
							<td class="playerstats_row">', $txt['dotastats_creepkills'], '</td>
							<td><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $player['topcreepkillsgameid'], '">', $player['topcreepkills'], '</a></td>
							<td>', number($player['avgcreepkills'], 2), '</td>
							<td>', number($player['totalcreepkills'], 0), '</td>
						</tr>
						<tr>
							<td class="playerstats_row">', $txt['dotastats_creepdenies'], '</td>
							<td><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $player['topcreepdeniesgameid'], '">', $player['topcreepdenies'], '</a></td>
							<td>', number($player['avgcreepdenies'], 2), '</td>
							<td>', number($player['totalcreepdenies'], 0), '</td>
						</tr>
						<tr>
							<td class="playerstats_row">', $txt['dotastats_neutralkills'], '</td>
							<td><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=' ,$player['topneutralkillsgameid'], '">', $player['topneutralkills'], '</a></td>
							<td>', number($player['avgneutralkills'], 2), '</td>
							<td>', number($player['totalneutralkills'], 0), '</td>
						</tr>
						<tr>
							<td class="playerstats_row">', $txt['dotastats_towerkills'], '</td>
							<td><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $player['toptowerkillsgameid'], '">', $player['toptowerkills'], '</a></td>
							<td>', number($player['avgtowerkills'], 2), '</td>
							<td>', number($player['totaltowerkills'], 0), '</td>
						</tr>
						<tr>
							<td class="playerstats_row">', $txt['dotastats_raxkills'], '</td>
							<td><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $player['topraxkillsgameid'], '">', $player['topraxkills'], '</a></td>
							<td>', number($player['avgraxkills'], 2), '</td>
							<td>', number($player['totalraxkills'], 0), '</td>
						</tr>
						<tr>
							<td class="playerstats_row">', $txt['dotastats_courierkills'], '</td>
							<td><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $player['topcourierkillsgameid'], '">', $player['topcourierkills'], '</a></td>
							<td>', number($player['avgcourierkills'], 2), '</td>
							<td>', number($player['totalcourierkills'], 0), '</td>
						</tr>
					</tbody>
				</table>
			</div>
			<h3>', $txt['dotastats_gamestats'], '</h3>
			<div id="playerdetail_subcontainer">
				<ul>
					<li><span class="stat_title">', $txt['dotastats_gamesplayed'], '</span><span>', $player['gamesplayed'], '</span></li>
					<li><span class="stat_title">', $txt['dotastats_gamesday'], '</span><span>', $player['gamesperday'], '</span></li>
					<li><span class="stat_title">', $txt['dotastats_gameswon'], '</span><span>', $player['wins'], '</span></li>
					<li><span class="stat_title">', $txt['dotastats_gameslost'], '</span><span>', $player['losses'], '</span></li>
					<li><span class="stat_title">', $txt['dotastats_quickvictory'], '</span><span><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $player['fastgamewonid'], '">', number(($player['fastgamewon'] / 60),0), 'm ', ($player['fastgamewon'] % 60), 's</a></span></li>
					<li><span class="stat_title">', $txt['dotastats_quicklost'], '</span><span><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $player['fastgamelossid'], '">', number(($player['fastgameloss'] / 60),0), 'm ', ($player['fastgameloss'] % 60), 's</a></span></li>
					<li><span class="stat_title">', $txt['dotastats_longgamewon'], '</span><span><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $player['longgamewonid'], '">', number(($player['longgamewon'] / 60),0), 'm ', ($player['longgamewon'] % 60), 's</a></span></li>
					<li><span class="stat_title">', $txt['dotastats_longgamelost'], '</span><span><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $player['longgamelossid'], '">', number(($player['longgameloss'] / 60),0), 'm ', ($player['longgameloss'] % 60), 's</a></span></li>
					<li><span class="stat_title">', $txt['dotastats_firstgameplay'], '</span><span><a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $player['firstgameid'], '">', $player['firstgame'], '</a></span></li>
					<li><span class="stat_title">', $txt['dotastats_recentgames'], '</span>
						<ul id="recentgames">';
			
				// Output the players most recent games
				foreach ($player['recentgames'] as $recentgame)
				{
					echo '
					<li>';
				
					if (isset($recentgame['icon']) && !is_null($recentgame['icon']))
						echo '
						<img src="', $settings['images_url'], '/dotastats/heroes/', $recentgame['icon'], '.gif" title="', $recentgame['title'], '" />';
					else
						echo '
						<img src="', $settings['images_url'], '/dotastats/heroes/Invalid.gif" title="', $txt['dotastats_nohero'], '" />';
						
					echo ' ', $recentgame['gamestatus'],', ', $recentgame['kills'], '-', $recentgame['deaths'], '-', $recentgame['assists'], ', <a href="', $scripturl, '?action=dotastats;sa=gamedetail;gameid=', $recentgame['gameid'], '">', $recentgame['datetime'], '</a>
					</li>';
				}
						
				echo '
						</ul>
						<div class="clearfix"></div>
					</li>
					<li><span class="stat_title">', $txt['dotastats_avggame'], '</span><span>', number(($player['avggamelength'] / 60),0), 'm ', ($player['avggamelength'] % 60), 's</span></li>
					<li><span class="stat_title">', $txt['dotastats_bestload'], '</span><span>', $player['bestloadtime'], 's</span></li>
				</ul>
			</div>
			<h3>', $txt['dotastats_herostats'], '</h3>
			<div id="playerdetail_subcontainer">
				<ul>
					<li>
						<span class="stat_title">', $txt['dotastats_popheroes'], '</span>
						<div class="herostat_imagelist">';
			
				for ($i = 0; $i < 5; $i++)
					echo '
							<div class="herostat_image" style="background-image: url(', $settings['images_url'], '/dotastats/heroes/', $player['popularheroes'][$i]['icon'], '.gif);" title="', $player['popularheroes'][$i]['name'],'">
								<div class="herostat_frame">
									<div class="overlay"></div>
									<div class="herostat_content">
										<span>', $player['popularheroes'][$i]['timesplayed'], '</span>
									</div>
								</div>
							</div>';
					
				echo '
						</div>
					</li>';
			
				// If the player has played every hero, output their least played heroes.
				if (count($player['unplayedheroes']) == 0)
				{
					echo '
					<li>
						<span class="stat_title">', $txt['dotastats_unpopheroes'], '</span>
						<div class="herostat_imagelist">';
			
					for ($i = 0; $i < 5; $i++)
						echo '
							<div class="herostat_image" style="background-image: url(', $settings['images_url'], '/dotastats/heroes/', $player['unpopularheroes'][$i]['icon'], '.gif);" title="', $player['unpopularheroes'][$i]['name'],'">
								<div class="herostat_frame">
									<div class="overlay"></div>
									<div class="herostat_content">
										<span>', $player['unpopularheroes'][$i]['timesplayed'], '</span>
									</div>
								</div>
							</div>';
					
					echo '
						</div>
					</li>';
				}
			
				// Output the players best average hero scores
				echo '
					<li>
						<span class="stat_title">', $txt['dotastats_bestscore'], '</span>
						<div class="herostat_imagelist">';
			
				for ($i = 0; $i < 5; $i++)
					echo '
							<div class="herostat_image" style="background-image: url(', $settings['images_url'], '/dotastats/heroes/', $player['bestheroscores'][$i]['icon'], '.gif);" title="', $player['bestheroscores'][$i]['name'],'">
								<div class="herostat_frame">
									<div class="overlay"></div>
									<div class="herostat_content">
										<span>', number($player['bestheroscores'][$i]['avgkills'], 0), '-', number($player['bestheroscores'][$i]['avgdeaths'], 0), '-', number($player['bestheroscores'][$i]['avgassists'], 0), '</span>
									</div>
								</div>
							</div>';
			
				// Output the players worst average hero scores
				echo '
						</div>
					</li>
					<li>
						<span class="stat_title">', $txt['dotastats_worstscore'], '</span>
						<div class="herostat_imagelist">';
										
				for ($i = 0; $i < 5; $i++)
					echo '
							<div class="herostat_image" style="background-image: url(', $settings['images_url'], '/dotastats/heroes/', $player['worstheroscores'][$i]['icon'], '.gif);" title="', $player['worstheroscores'][$i]['name'],'">
								<div class="herostat_frame">
									<div class="overlay"></div>
									<div class="herostat_content">
										<span>', number($player['worstheroscores'][$i]['avgkills'], 0), '-', number($player['worstheroscores'][$i]['avgdeaths'], 0), '-', number($player['worstheroscores'][$i]['avgassists'], 0), '</span>
									</div>
								</div>
							</div>';
					
				echo '
						</div>
					</li>';
			
				// If the player has unplayed heroes . . .
				if (count($player['unplayedheroes']) > 0)
				{
					echo '
						<li>
							<span class="stat_title">', $txt['dotastats_unplayed'], '</span>
							<div class="herostat_imagelist">', count($player['unplayedheroes']), '</div><span id="unplayed_toggle" class="ds_button ui-state-default ui-corner-all">Show</span>
							<div id="unplayed_content">';

					foreach ($player['unplayedheroes'] as $key => $hero)
						echo '
								<img class="hero" src="', $settings['images_url'], '/dotastats/heroes/', $hero['icon'], '.gif" title="', $key, '" />';

					echo '
							</div>
						</li>';
				}
				
				echo '
					</ul>';
					
			
				echo '
				<div class="clearfix"></div>
			</div>
		</div>
	</div>';
			}
			else
				echo '<div id="ds_game_error" class="ui-state-error ui-corner-all"><p>Not enough games played.</p></div>';
			break;
			
		// Output the game detail page
		case 'gamedetail':
			$gamedetail = $context['dotastats']['gamedetail'];
			if ($gamedetail['playercount'] <= 1)
				echo '<div id="ds_game_error" class="ui-state-error ui-corner-all"><p><span class="ui-icon ui-icon-alert"></span>', $txt['dotastats_zerogame'], '</p></div>';
			else
			{
				echo '
	<div id="gamedetail">
		<div id="sentinel" style="background-color: #', WinLossColor($gamedetail['winner'], 1) ,';">
			<h1 id="sentinel_title">', $txt['dotastats_sentinel'], '</h1>';
			
				// Loop through player slots 1 - 5
				for ($i = 1; $i <= 5; $i++)
				{
					// Check to make sure this slot was not empty and the player picked a hero
					if (isset($gamedetail['players'][$i]) && !empty($gamedetail['players'][$i]['heroname']))
					{	
						echo '
			<div class="player_frame">
				<div class="player_frame_padding">';
				
						if ($gamedetail['players'][$i]['banned'])
							echo '
					<div class="overlay"></div>
					<span class="banned_title">BANNED!</span>';
				
						echo '
					<h3><a class="player', $i, '" href="', $scripturl, '?action=dotastats;sa=playerdetail;name=', $gamedetail['players'][$i]['name'], '">', $gamedetail['players'][$i]['name'], '</a></h3>
					<img class="hero" src="', $settings['images_url'], '/dotastats/heroes/', $gamedetail['players'][$i]['icon'], '.gif" title="', $gamedetail['players'][$i]['heroname'], '" />
					<div class="item_frame">';
				
					for ($x = 1; $x <= 6; $x++)
					{
						$item = trim($gamedetail['players'][$i]['item'.$x]);
						if (!empty($item))
							echo '
						<img class="small_item" src="', $settings['images_url'], '/dotastats/items/', strtolower($item), '.gif" />';
						else
							echo '
						<img class="small_item" src="', $settings['images_url'], '/dotastats/items/empty.gif" />';
					}
				
					echo '
					</div>
					<ul>
						<li><span class="stat_title">', $txt['dotastats_kda'], '</span><span>', $gamedetail['players'][$i]['kills'], '-', $gamedetail['players'][$i]['deaths'], '-' ,$gamedetail['players'][$i]['assists'], '</span></li>
						<li><span class="stat_title">', $txt['dotastats_denies'], '</span><span>', $gamedetail['players'][$i]['creepdenies'], '</span></li>
						<li><span class="stat_title">', $txt['dotastats_creeps'], '</span><span>', $gamedetail['players'][$i]['creepkills'], '</span></li>
						<li><span class="stat_title">', $txt['dotastats_neutrals'], '</span><span>', $gamedetail['players'][$i]['neutralkills'], '</span></li>
						<li><span class="stat_title">', $txt['dotastats_towers'], '</span><span>', $gamedetail['players'][$i]['towerkills'], '</span></li>
						<li><span class="stat_title">', $txt['dotastats_rax'], '</span><span>', $gamedetail['players'][$i]['raxkills'], '</span></li>
					</ul>
				</div>
			</div>';
					}
					elseif (isset($gamedetail['players'][$i]) && !empty($gamedetail['players'][$i]))
					{
						echo '
			<div class="player_frame">
				<div class="player_frame_padding">';
						
						if ($gamedetail['players'][$i]['banned'])
							echo '
					<div class="overlay"></div>
					<span class="banned_title">BANNED!</span>';
					
						echo '
					<h3><a class="player', $i, '" href="', $scripturl, '?action=dotastats;sa=playerdetail;name=', $gamedetail['players'][$i]['name'], '">', $gamedetail['players'][$i]['name'], '</a></h3>
					<em>', $txt['dotastats_nohero'], '</em>
				</div>
			</div>';
					}
					else
					{
						echo '
			<div class="player_frame">
				<div class="player_frame_padding">';
						
						if ($gamedetail['players'][$i]['banned'])
							echo '
					<div class="overlay"></div>
					<span class="banned_title">BANNED!</span>';
					
						echo '
					', $txt['dotastats_empty'], '
				</div>
			</div>';
					}
				}
				
				echo '
			<div class="clearfix"></div>
		</div>
		<div id="results">
			<div id="sentinel_results">
				<div class="results_detail">';

				if ($gamedetail['winner'] == 1)
					echo '
					<h1>', $txt['dotastats_win'], '</h1>';
				elseif ($gamedetail['winner'] == 2)
					echo '
					<h1>', $txt['dotastats_loss'], '</h1>';
				else
					echo '
					<h1>', $txt['dotastats_gameincomplete'], '</h1>';
				
				echo '
					<h4>', $txt['dotastats_teamstats'], '</h4>
					<ul>
						<li><span class="stat_title">', $txt['dotastats_kda'], '</span><span>', $gamedetail['sentinel']['totalkills'], '</span>-<span>', $gamedetail['sentinel']['totaldeaths'], '</span>-<span>', $gamedetail['sentinel']['totalassists'], '</span></li>
						<li><span class="stat_title">', $txt['dotastats_denies'], '</span><span></span>', $gamedetail['sentinel']['totalcreepdenies'], '</li>
						<li><span class="stat_title">', $txt['dotastats_creeps'], '</span><span></span>', $gamedetail['sentinel']['totalcreepkills'], '</li>
						<li><span class="stat_title">', $txt['dotastats_neutrals'], '</span><span></span>', $gamedetail['sentinel']['totalneutralkills'], '</li>
						<li><span class="stat_title">', $txt['dotastats_towers'], '</span><span>', $gamedetail['sentinel']['totaltowerkills'], '</span></li>
						<li><span class="stat_title">', $txt['dotastats_rax'], '</span><span>', $gamedetail['sentinel']['totalraxkills'], '</span></li>
					</ul>
				</div>
			</div>
			<div id="game_results">
				<ul>
					<li><h2>', $txt['dotastats_game'], ' ', $gamedetail['gameid'], '</h2></li>
					<li><h2>', $gamedetail['gamename'], '</h2></li>
					<li><h2>', $txt['dotastats_version'], ' ', $gamedetail['version'], '</h2></li>
					<li><h2>', $gamedetail['min'], 'm ', $gamedetail['sec'], 's</h2></li>
				</ul>
			</div>
			<div id="scourge_results">
				<div class="results_detail">';

				if ($gamedetail['winner'] == 2)
					echo '
					<h1>', $txt['dotastats_win'], '</h1>';
				elseif ($gamedetail['winner'] == 1)
					echo '
					<h1>', $txt['dotastats_loss'], '</h1>';
				else
					echo '
					<h1>', $txt['dotastats_gameincomplete'], '</h1>';
				
				echo '
					<h4>', $txt['dotastats_teamstats'], '</h4>
					<ul>
						<li><span class="stat_title">', $txt['dotastats_kda'], '</span><span>', $gamedetail['scourge']['totalkills'], '</span>-<span>', $gamedetail['scourge']['totaldeaths'], '</span>-<span>', $gamedetail['scourge']['totalassists'], '</span></li>
						<li><span class="stat_title">', $txt['dotastats_denies'], '</span><span></span>', $gamedetail['scourge']['totalcreepdenies'], '</li>
						<li><span class="stat_title">', $txt['dotastats_creeps'], '</span><span ></span>', $gamedetail['scourge']['totalcreepkills'], '</li>
						<li><span class="stat_title">', $txt['dotastats_neutrals'], '</span><span></span>', $gamedetail['scourge']['totalneutralkills'], '</li>
						<li><span class="stat_title">', $txt['dotastats_towers'], '</span><span>', $gamedetail['scourge']['totaltowerkills'], '</span></li>
						<li><span class="stat_title">', $txt['dotastats_rax'], '</span><span>', $gamedetail['scourge']['totalraxkills'], '</span></li>
					</ul>
				</div>
			</div>
			<div class="clearfix"></div>
		</div>
		<div id="scourge" style="background-color: #', WinLossColor($gamedetail['winner'], 2) ,';">';
			
				// Ouput players 6 - 10, represented internally as 7 - 11
				for ($i = 7; $i <= 11; $i++)
				{
					// Check to make sure this slot was not empty and the player picked a hero
					if (isset($gamedetail['players'][$i]) && !empty($gamedetail['players'][$i]['heroname']))
					{	
						echo '
			<div class="player_frame">
				<div class="player_frame_padding">';
				
						if ($gamedetail['players'][$i]['banned'])
							echo '
					<div class="overlay"></div>
					<span class="banned_title">BANNED!</span>';
				
						echo '
					<h3><a class="player', $i, '" href="', $scripturl, '?action=dotastats;sa=playerdetail;name=', $gamedetail['players'][$i]['name'], '">', $gamedetail['players'][$i]['name'], '</a></h3>
					<img class="hero" src="', $settings['images_url'], '/dotastats/heroes/', $gamedetail['players'][$i]['icon'], '.gif" title="', $gamedetail['players'][$i]['heroname'], '" />
					<div class="item_frame">';
				
					for ($x = 1; $x <= 6; $x++)
					{
						$item = trim($gamedetail['players'][$i]['item'.$x]);
						if (!empty($item))
							echo '
						<img class="small_item" src="', $settings['images_url'], '/dotastats/items/', strtolower($item), '.gif" />';
						else
							echo '
						<img class="small_item" src="', $settings['images_url'], '/dotastats/items/empty.gif" />';
					}
				
					echo '
					</div>
					<ul>
						<li><span class="stat_title">', $txt['dotastats_kda'], '</span><span>', $gamedetail['players'][$i]['kills'], '-', $gamedetail['players'][$i]['deaths'], '-' ,$gamedetail['players'][$i]['assists'], '</span></li>
						<li><span class="stat_title">', $txt['dotastats_denies'], '</span><span>', $gamedetail['players'][$i]['creepdenies'], '</span></li>
						<li><span class="stat_title">', $txt['dotastats_creeps'], '</span><span>', $gamedetail['players'][$i]['creepkills'], '</span></li>
						<li><span class="stat_title">', $txt['dotastats_neutrals'], '</span><span>', $gamedetail['players'][$i]['neutralkills'], '</span></li>
						<li><span class="stat_title">', $txt['dotastats_towers'], '</span><span>', $gamedetail['players'][$i]['towerkills'], '</span></li>
						<li><span class="stat_title">', $txt['dotastats_rax'], '</span><span>', $gamedetail['players'][$i]['raxkills'], '</span></li>
					</ul>
				</div>
			</div>';
					}
					elseif (isset($gamedetail['players'][$i]) && !empty($gamedetail['players'][$i]))
					{
						echo '
			<div class="player_frame">
				<div class="player_frame_padding">';
						
						if ($gamedetail['players'][$i]['banned'])
							echo '
					<div class="overlay"></div>
					<span class="banned_title">BANNED!</span>';
					
						echo '
					<h3><a class="player', $i, '" href="', $scripturl, '?action=dotastats;sa=playerdetail;name=', $gamedetail['players'][$i]['name'], '">', $gamedetail['players'][$i]['name'], '</a></h3>
					<em>', $txt['dotastats_nohero'], '</em>
				</div>
			</div>';
					}
					else
					{
						echo '
			<div class="player_frame">
				<div class="player_frame_padding">';
						
						if ($gamedetail['players'][$i]['banned'])
							echo '
					<div class="overlay"></div>
					<span class="banned_title">BANNED!</span>';
					
						echo '
					', $txt['dotastats_empty'], '
				</div>
			</div>';
					}
				}
				
				echo '
				<div class="clearfix"></div>
				<h1 id="scourge_title">', $txt['dotastats_scourge'], '</h1>
			</div>
			<script>
				$(document).ready(function(){
					$(".player_frame").gradient({
						from:      "E0E0E0",
						to:        "FFFFFF"
					});
					$("#sentinel_results > .results_detail").gradient({
						from:      "', WinLossColor($gamedetail['winner'], 1) ,'",
						to:        "FFFFFF"
					});
					$("#sentinel_title").gradient({
						from:      "FFFFFF",
						to:        "', WinLossColor($gamedetail['winner'], 1) ,'"
					});
					$("#scourge_results > .results_detail").gradient({
						from:      "FFFFFF",
						to:        "', WinLossColor($gamedetail['winner'], 2) ,'"
					});
					$("#scourge_title").gradient({
						from:        "', WinLossColor($gamedetail['winner'], 2) ,'",
						to:      "FFFFFF"
					});
				});
			</script>
		</div>';
		}
			break;
			
		case 'herolist':
			break;
		
		
		case 'adminlist':
			break;
			
		default:
			break;
	}
}

?>